package com.gxa.controller;

import com.gxa.common.Constants;
import com.gxa.common.PageRecv;
import com.gxa.common.R;
import com.gxa.pojo.*;
import com.gxa.service.CustomerPoolService;
import com.gxa.service.CustomerService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: erp
 * @description: 客户公海相关接口
 * @author: LC
 * @create: 2021-12-03 15:50
 */

@Controller
@RequestMapping("/customerPool")
@Api(value="客户公海接口Test",tags = "客户公海接口（李晨）")
public class CustomerPoolController {

    @Autowired(required = true)
    CustomerPoolService customerPoolService;


    @ApiOperation(value = "查询客户公海信息",notes = "用分页的方式查询客户信息,返回的是数组", response = R.class)
    @RequestMapping(value = "/getPage",method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerInfo(@RequestBody @ApiParam(name = "pageRecv",value = "分页json",required = true) PageRecv<Customer_Pool> pageRecv) {
        R r=customerPoolService.getCustomerPoolPage(pageRecv);
        return r;
    }



    @ApiOperation(value = "查询客户公海搜索",notes = "用分页的方式查询客户信息,返回的是数组", response = R.class)
    @RequestMapping(value = "/getCustomerPoolBySearch",method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerPoolBySearch(@RequestBody @ApiParam(name = "pageRecv",value = "分页json",required = true) PageRecv<Customer_Pool> pageRecv) {
        R r=customerPoolService.getCustomerPoolPage(pageRecv);
        return r;
    }


    /**
     * 公海：申请，通过，拒绝，高级搜索
     *
     * 问题记录：改状态应该前端传递状态码统一调用一个接口，还是该修改每种状态都写一个接口
     */

    @ApiOperation(value = "业务员申请客户",notes = "业务员申请客户", response = R.class)
    @RequestMapping(value = "/applyCustomer",method = RequestMethod.POST)
    @ApiImplicitParam(name = "customerPoolIds", value = "客户记录id数组", required = true, allowMultiple = true)
    @ResponseBody
    public R applyCustomer(@RequestBody List<Integer> customerPoolIds) {
        R r=customerPoolService.applyCustomer(customerPoolIds);
        return r;
    }

    @ApiOperation(value = "审核是否分配客户",notes = "需要传递customer的id，employee的id, cp_id和审核结果：3（通过），2（拒绝）", response = R.class)
    @RequestMapping(value = "/reviewApplication",method = RequestMethod.POST)
    @ResponseBody
    public R reviewApplication(@RequestBody @ApiParam(name = "customer_Pools", value = "需要传递customer的id，employee的id, cp_id和审核结果：3（通过），2（拒绝）", required = true) List<Customer_Pool> customer_Pools) {
        R r=customerPoolService.reviewApplication(customer_Pools);
        return r;
    }

//----------------------------------


    @ApiOperation(value = "转移客户到指定业务员", notes = "把客户转交给指定的业务员对接\n" +
            "customerIds（客户id数组），employeeId员工编号", response = R.class)
    @RequestMapping(value = "/moveToOtherEmp", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerIds", value = "客户数组", required = true,allowMultiple = true),
            @ApiImplicitParam(name = "employeeId", value = "业务员id", required = true) })
    @ResponseBody
//    public R moveToOtherEmp(@RequestParam List<Integer> customerIds,
//                            @RequestParam Integer employeeId) {
    public R moveToOtherEmp(@RequestBody Map body) {
        R r = customerPoolService.moveToOtherEmp((List)body.get("customerIds"), (Integer)body.get("employeeId"));
        return r;
    }


    @ApiOperation(value = "批量移动客户到回收站", notes = "批量的将客户移到回收站中，传入的参数是一个客户id数组，若要移动一个客户也需要放到数组中，可复用该接口\n" +
            "customerIds（客户id数组），remark（备注），delInfo（删除相关信息编号数组，可暂时只写个0）", response = R.class)
    @ApiImplicitParam(name = "customerIds", value = "移动到回收站的客户id数组", paramType = "query", dataType = "Integer", allowMultiple = true, required = false)
    @RequestMapping(value = "/moveToTrash", method = RequestMethod.POST)
    @ResponseBody
//    public R moveToTrash(@RequestParam List<Integer> customerIds, @RequestParam String remark, @RequestParam List<Integer> delInfo) {
    public R moveToTrash(@RequestBody Map body) {
        R r = customerPoolService.moveToTrash((List)body.get("customerIds"), (String) body.get("remark"), (List)body.get("delInfo"));
        return r;
    }

    @ApiOperation(value = "新增客户", notes = "新增一个客户", response = R.class)
    @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
    @ResponseBody
    public R addCustomer(@RequestBody @ApiParam(name = "customer", value = "新增的客户实体", required = true) Customer customer) {
        R r = customerPoolService.addCustomer(customer);
        return r;
    }

    @ApiOperation(value = "修改客户", notes = "修改客户的信息，需要传入客户实体", response = R.class)
    @RequestMapping(value = "/modifyCustomer", method = RequestMethod.POST)
    @ResponseBody
    public R modifyCustomer(@RequestBody @ApiParam(name = "customer", value = "修改后的客户实体", required = true) Customer customer) {
        R r = customerPoolService.modifyCustomer(customer);
        return r;
    }

    @ApiOperation(value = "待审核数量", notes = "待审核数量", response = R.class)
    @RequestMapping(value = "/getCountByApplication", method = RequestMethod.POST)
    @ResponseBody
    public R getCountByApplication() {
        R r = customerPoolService.getCountByApplication();
        return r;
    }

    @ApiOperation(value = "待审核公海数据", notes = "待审核公海数据", response = R.class)
    @RequestMapping(value = "/getCustomerPoolByApplication", method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerPoolByApplication(@RequestBody @ApiParam(name = "pageRecv",value = "分页json",required = true) PageRecv<Customer_Pool> pageRecv) {
        R r = customerPoolService.getCustomerPoolByApplication(pageRecv);
        return r;
    }


}